<%--
  - Author		:	Jaewon Choi
  --%>
<%@ page language="java" %>
<%@ page contentType="text/html; charset=utf-8" %>
<%@ page pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/pages/includes/taglibs.jspf" %>
<%@ include file="/WEB-INF/pages/includes/variables.jspf" %>
<%@ include file="/WEB-INF/pages/includes/doctype.jspf" %>
<c:choose>
	<c:when test="${not empty content}">
		<c:set var="fAct" value="수정" />
	</c:when>
	<c:otherwise>
		<c:set var="fAct" value="등록" />
	</c:otherwise>
</c:choose>
<html>
	<head>
<%@ include file="/WEB-INF/pages/includes/metatags.jspf" %>
		<title><fmt:message key="pages.title" /></title>
		<link rel="stylesheet" type="text/css" href="<c:url value="${dirStyles}/common.css" />" />

		<link rel="stylesheet" type="text/css" href="<c:url value="${dirScripts}/jqueryUi/css/ui-lightness/jquery-ui-1.8.21.custom.css" />" />

		<script type="text/javascript" src="<c:url value="${dirScripts}/jquery-1.7.2.min.js" />"></script>
		<script type="text/javascript" src="<c:url value="${dirScripts}/jquery-ui-1.8.21.custom.min.js" />"></script>
		<script type="text/javascript">
			$(function(){
				$("#name").focus();
				
				$( ".date" ).datepicker({
					showOn: "both",
					buttonImage: "<c:url value="${dirImages}/calendar.png" />",
					buttonImageOnly: true,
					dateFormat: "yy-mm-dd",
					showWeek: true
				});
			});
			
			function chkContNm(){
				var idx = "0";
				var name = document.frm.name.value;
				if(document.frm.idx){
					idx = document.frm.idx.value;
				}
				
				$.ajax({
					type: "POST",
					url: "<c:url value="/content/chkDupl" />",
					dataType: "json",
					async: false,
					data: {
								"idx" : idx,
								"chkName" : name
							},
					success: function(data){
						if(data.resultCode == "200"){
							chkContNmFlag = data.result;
							if(eval(chkContNmFlag)){
								$(document.frm.name).css("background", "#ADC900");
							}else{
								$(document.frm.name).css("background", "#F2685E");
							}
						}else{
							alert(data.errMsg);
						}
					},
					beforeSend: function(){
					},
					error: function(jqXHR, textStatus, errorThrown){
						//alert(jqXHR.responseText); //에러 페이지 내용
						alert("오류가 발생하였습니다.\n관리자에게 문의 바랍니다.");
						throw errorThrown;
					},
					complete: function(){
					}
				 });
				return eval(chkContNmFlag);
			}
			
			/*
			 * 숫자(정수) 형식 여부
			 */
			function isOnlyNumber(source) {
				var pattern = /^[0-9]+$/;
				
				return pattern.test(source);
			}
			
			function validation(){
				try{
					
				}catch(err){
					return false;	
				}
				
				return confirm("${fAct} 하시겠습니까?");
			}			

		</script>
	</head>
	<body>
		<div class="bodyWrap">
<%@ include file="/WEB-INF/pages/includes/header.jsp" %>
<%@ include file="/WEB-INF/pages/includes/left.jsp" %>
			<div class="contWrap">
				<div class="menuTitle">
					콘텐츠 ${fAct}
				</div>
				<form id="frm" name="frm" method="post" enctype="multipart/form-data" action="<c:url value="/content/submit.do" />" onsubmit="return validation();">
					<input type="hidden" name="maxnum" value="${param.maxnum}" />
					<input type="hidden" name="page" value="${param.page}" />
					<input type="hidden" name="searchDate" value="${param.searchDate}">
					<input type="hidden" name="startDate" value="${param.startDate}" /> 
					<input type="hidden" name="endDate" value="${param.endDate}" />
					<input type="hidden" name="searchName" value="${param.searchName}" />
					<input type="hidden" name="searchCategoryId" value="${param.searchCategoryId}" />
					<input type="hidden" name="userIdx" value="1" />
					
					<table class="frmTbl">
						<colgroup>
							<col width="176px;" />
							<col width="*" />
							<col width="100px;" />
							<col width="*" />
						</colgroup>
						<tbody>	
			 				<c:if test="${not empty content}">
			 					<tr>
									<th>콘텐츠 IDX</th>
									<td colspan="3">
										${content.idx}
										<input type="hidden" name="idx" value="${content.idx}">
									</td>
								</tr>
			 				</c:if>
			 				<tr>
								<th>카테고리 *</th>
								<td colspan="3">
								<select name="categoryIdx">
									<c:forEach items="${categoryList}" var="category" varStatus="cateStat">									
											<label>
													<option value="${category.idx}" <c:if test="${(not empty content.idx && category.idx eq content.categoryIdx)}">selected</c:if>>${category.name}												
											</label>
									</c:forEach>
								</select>
								</td>
							</tr>
							<tr>
								<th>제목 *</th>
								<td>
									<input type="text" id="title" name="title" value="${content.title}" />
								</td>
								<th>사건 일자 *</th>
								<td>
									<input type="text" class="date" name="happenDate" readonly="readonly" value="<c:if test="${not empty content}">${content.happenDate}</c:if>" />									
								</td>
							</tr>
							<tr>
								<th>사건 시간대 *</th>
								<td colspan="3">
									<select name="happenTime">
										<option value="1" <c:if test="${content.happenTime eq '1'}">selected</c:if>>1:00~1:59
										<option value="2" <c:if test="${content.happenTime eq '2'}">selected</c:if>>2:00~2:59
										<option value="3" <c:if test="${content.happenTime eq '3'}">selected</c:if>>3:00~3:59
										<option value="4" <c:if test="${content.happenTime eq '4'}">selected</c:if>>4:00~4:59
										<option value="5" <c:if test="${content.happenTime eq '5'}">selected</c:if>>5:00~5:59
										<option value="6" <c:if test="${content.happenTime eq '6'}">selected</c:if>>6:00~6:59
										<option value="7" <c:if test="${content.happenTime eq '7'}">selected</c:if>>7:00~7:59
										<option value="8" <c:if test="${content.happenTime eq '8'}">selected</c:if>>8:00~8:59
										<option value="9" <c:if test="${content.happenTime eq '9'}">selected</c:if>>9:00~9:59
										<option value="10" <c:if test="${content.happenTime eq '10'}">selected</c:if>>10:00~10:59
										<option value="11" <c:if test="${content.happenTime eq '11'}">selected</c:if>>11:00~11:59
										<option value="12" <c:if test="${content.happenTime eq '12'}">selected</c:if>>12:00~12:59
										<option value="13" <c:if test="${content.happenTime eq '13'}">selected</c:if>>13:00~13:59
										<option value="14" <c:if test="${content.happenTime eq '14'}">selected</c:if>>14:00~14:59
										<option value="15" <c:if test="${content.happenTime eq '15'}">selected</c:if>>15:00~15:59
										<option value="16" <c:if test="${content.happenTime eq '16'}">selected</c:if>>16:00~16:59
										<option value="17" <c:if test="${content.happenTime eq '17'}">selected</c:if>>17:00~17:59
										<option value="18" <c:if test="${content.happenTime eq '18'}">selected</c:if>>18:00~18:59
										<option value="19" <c:if test="${content.happenTime eq '19'}">selected</c:if>>19:00~19:59
										<option value="20" <c:if test="${content.happenTime eq '20'}">selected</c:if>>20:00~20:59
										<option value="21" <c:if test="${content.happenTime eq '21'}">selected</c:if>>21:00~21:59
										<option value="22" <c:if test="${content.happenTime eq '22'}">selected</c:if>>22:00~22:59
										<option value="23" <c:if test="${content.happenTime eq '23'}">selected</c:if>>23:00~23:59
										<option value="24" <c:if test="${content.happenTime eq '24'}">selected</c:if>>00:00~00:59
									</select>
								</td>								
							</tr>
							<tr>
								<th>위도 *</th>
								<td>
									<input type="text" id="latitude" name="latitude" value="${content.latitude}" />
								</td>
								<th>경도 *</th>
								<td>
									<input type="text" id="longitude" name="longitude" value="${content.longitude}" />									
								</td>
							</tr>
							<tr>
								<th>설명 *</th>
								<td colspan="3">
									<textarea name="contDesc" style="height: 150px; width: 620px;">${content.contDesc}</textarea>
								</td>
							</tr>
							<tr>
								<th>현상금 *</th>
								<td >
									<input type="text" id="reward" name="reward" value="${content.reward}" />	
								</td>
								<th>종료여부 *</th>
								<td >
									<select name="finish">
										<option value="0" <c:if test="${content.finish eq 0}">selected</c:if>>진행중
										<option value="1" <c:if test="${content.finish eq 1}">selected</c:if>>종료
									</select>
								</td>
							</tr>
							<c:choose>
								<c:when test="${not empty content}">
									<tr>
										<th rowspan="13">이미지</th>
										<th colspan="3">등록된 파일을 삭제하려면 체크 박스를 선택하고 하단의 수정 버튼을 누르면 됩니다.</th>
									</tr>
								</c:when>
								<c:otherwise>
									<tr>
										<th rowspan="13">이미지</th>
									</tr>
								</c:otherwise>
							</c:choose>
							<c:forEach var="mainImg" items="${mainImgs}" varStatus="stat">
								<tr>
									<td colspan="3">
										<input type="checkbox" name="contFileIdx" value="${mainImg.idx}" />
										<img src="${mainImg.fileUrl}" class="thumbnailImg" />
									</td>				
								</tr>
							</c:forEach>
							<c:forEach var="i" begin="0" end="${5-fn:length(mainImgs)}" step="1" varStatus="stat">
								<tr>
									<td colspan="3">
										<input type="file" name="contFiles[${i}]" />
										<input type="hidden" name="contFileTypes" value="mainImg" />
										<input type="hidden" name="emblems" value="X" />
										<input type="hidden" name="contFileDatas" value="" />
									</td>								
								</tr>
							</c:forEach>
						</tbody>
					</table>
					<input type="button" class="btn" value="취소" onclick="javascript:document.listFrm.submit();" />
					<input type="submit" class="btn" value="${fAct}" />
					<c:if test="${not empty content}">
						<input type="button" class="btn" value="삭제" onclick="javascript:if(confirm('삭제 하시겠습니까?')){document.removeFrm.submit();}" />
					</c:if>
				</form>
				<form name="listFrm" action="<c:url value="/content/list.do" />" method="post" style="display: none;">
					<input type="hidden" name="maxnum" value="${param.maxnum}" />
					<input type="hidden" name="page" value="${param.page}" />
					<input type="hidden" name="searchDate" value="${param.searchDate}">
					<input type="hidden" name="startDate" value="${param.startDate}" /> 
					<input type="hidden" name="endDate" value="${param.endDate}" />
					<input type="hidden" name="name" value="${param.searchName}" />
					<input type="hidden" name="categoryIdx" value="${param.searchCategoryIdx}" />
				</form>
				
				<form name="removeFrm" action="<c:url value="/content/remove.do" />" method="post" style="display: none;">
					<input type="hidden" name="fAct" value="remove">
					<input type="hidden" name="idx" value="${content.idx}">
					<input type="hidden" name="maxnum" value="${param.maxnum}" />
					<input type="hidden" name="page" value="${param.page}" />
					<input type="hidden" name="searchDate" value="${param.searchDate}">
					<input type="hidden" name="startDate" value="${param.startDate}" /> 
					<input type="hidden" name="endDate" value="${param.endDate}" />
					<input type="hidden" name="searchName" value="${param.searchName}" />
					<input type="hidden" name="searchCategoryIdx" value="${param.searchCategoryIdx}" />
				</form>
			</div>
<%@ include file="/WEB-INF/pages/includes/footer.jsp" %>
		</div>
	</body>
</html> 